using System;
using System.Collections.Generic;
using System.Text;
using TVDesigner.Entities.Elements;
using TVDesigner.Entities;

namespace TVDesigner.Generator.GeneratorEntities
{
    public class HButtonGenerator : HIconGenerator
    {
        private HButton _HButton;

        public HButtonGenerator(HButton hButton)
            : base(hButton)
        {
            _HButton = hButton;
        }
        
        public override string TypeString
        {
            get { return "org.havi.ui.HIcon"; }
        }

        public bool Focusable
        {
            get { return _HButton.Focusable; }
        }

        protected override void _SetAttributes(StringBuilder sb)
        {
            base._SetAttributes(sb);

            if (_HButton.FocusImage != null && !_HButton.FocusImage.Equals(string.Empty))
            {
                ImageFile imageFile = new ImageFile(_HButton.FocusImage);
                sb.Append("\t\t\tjava.awt.Image selectedImage = ImagesController.getInstance().getImage(\"").Append(imageFile.FileNameWithExtension).Append("\");\n");
                sb.Append("\t\t\tif (selectedImage != null) {\n");
                sb.Append("\t\t\t\t").Append(_HButton.NameStartedWithLowerCase).Append(".setGraphicContent(selectedImage, org.havi.ui.HVisible.FOCUSED_STATE);\n");
                sb.Append("\t\t\t}\n");
            }

            if (_HButton.Text != null && !_HButton.Text.Equals(string.Empty))
            {
                sb.Append("\t\t\tthis.").Append(_HButton.NameStartedWithLowerCase).Append(".setHorizontalAlignment(org.havi.ui.HText.HALIGN_LEFT);\n");
                sb.Append("\t\t\tthis.").Append(_HButton.NameStartedWithLowerCase).Append(".setVerticalAlignment(org.havi.ui.HText.VALIGN_TOP);\n");

                sb.Append("\t\t\tthis.").Append(_HButton.NameStartedWithLowerCase).Append(".setTextContent(\"").Append(_HButton.Text).Append("\", org.havi.ui.HVisible.ALL_STATES);\n");
                sb.Append("\t\t\tjava.awt.Font font = new java.awt.Font(\"Arial Black\", java.awt.Font.PLAIN, 20);\n");
                sb.Append("\t\t\t").Append(_HButton.NameStartedWithLowerCase).Append(".setFont(font);\n");

                sb.Append("\t\t\tjava.awt.Color color = new java.awt.Color(").Append(_HButton.TextColor.ToArgb()).Append(");\n");
                sb.Append("\t\t\tthis.").Append(_HButton.NameStartedWithLowerCase).Append(".setForeground(color);\n");

                sb.Append("\t\t\t//").Append(_HButton.NameStartedWithLowerCase).Append(".setBackground(org.dvb.ui.DVBColor.TRANSLUCENT);\n");
            }
        }
    }
}
